package com.yanqu.road.server.pb;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserBlacklist;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.player.BlacklistProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.manger.player.UserMgr;

import java.util.List;

public class BlacklistPb {
    public static BlacklistProto.BlacklistTempMsg.Builder parseBlacklistTempMsg(UserBlacklist userBlacklist){
        if(null == userBlacklist){
            return null;
        }
        BlacklistProto.BlacklistTempMsg.Builder msg = BlacklistProto.BlacklistTempMsg.newBuilder();
        msg.setBlacklistUserId(userBlacklist.getBlacklistUserId());
        msg.setBlacklistUserServerId(userBlacklist.getBlacklistUserServerId());
        msg.setIsDelete(userBlacklist.isDelete());
        if(!userBlacklist.isDelete()){
            UserBaseInfo baseInfo;
            if (GameServer.getInstance().getServerId() == userBlacklist.getBlacklistUserServerId()) {
                baseInfo = UserMgr.getUserBaseInfo(userBlacklist.getBlacklistUserId(), GameServer.getInstance().getServerId());
                if (null == baseInfo) {
                    return null;
                }
            } else {
                baseInfo = userBlacklist.getUserBaseInfo();
            }
            PlayerProto.PlayerBaseTempMsg.Builder baseTempMsg = PlayerBasePb.parsePlayerBaseTempMsg(baseInfo);
            msg.setBaseUserInfo(baseTempMsg);
        }
        msg.setType(userBlacklist.getType());
        return msg;
    }

    public static BlacklistProto.BlacklistListMsg.Builder parseBlacklistListMsg(List<UserBlacklist> userBlacklistList){
        BlacklistProto.BlacklistListMsg.Builder listMsg = BlacklistProto.BlacklistListMsg.newBuilder();
        if(null != userBlacklistList){
            for(UserBlacklist userBlacklist : userBlacklistList){
                BlacklistProto.BlacklistTempMsg.Builder msg = parseBlacklistTempMsg(userBlacklist);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }
}
